﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
using DAL;

public partial class Taotaikhoan_bacsi : System.Web.UI.Page
{
    THANHVIENBLL tvBll = new THANHVIENBLL();
    TAIKHOANBLL tkBll = new TAIKHOANBLL();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["tenthanhvien"] == null) Response.Redirect("LogIn.aspx");
        }
    }
    protected void btn_OK_Click(object sender, EventArgs e)
    {
        try
        {
            if (CustomValidator1.IsValid == true)
            {
                string str_ten = hoten.Text;
                string str_tentk = tentk.Text;
                string str_chucvu = chucvu.Text;
                string str_pass = pass.Text;
                string str_email = email.Text;

                tvBll.insertFast(str_ten, str_chucvu,str_email);
                THANHVIEN newtv = tvBll.getBestThanhvien();

                tkBll.insert(str_tentk, str_pass, newtv.mathanhvien, 2, 6);
                lb_kq.Text = "Thêm thành công !";
                lb_error.Text = " ";
            }
        }
        catch {
            lb_kq.Text = " ";
            lb_error.Text = "Nhập thông tin sai!";
        }
    }
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        try
        {
            if (tkBll.isExistTenTaikhoan(tentk.Text))
            {
                args.IsValid = false;
            }
            else
            {
                args.IsValid = true;
            }
        }
        catch
        {
            args.IsValid = false;
        }
    }
}
